#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os
import sys
import face_recognition
import cv2
import numpy as np
#from scipy.spatial.distance import pdist
from PIL import Image, ImageDraw, ImageFont
#from cv2 import  VideoCapture
import sqlite3
from imutils.video import VideoStream

import datetime
img=[]
frame=[]
q=0
start_time = datetime.datetime.now()
yyy=0
vs = VideoStream(src=0).start()

name=input('Введите табельный номер или ФИО: ')
name=str(name)
while True:
   frame = vs.read() 
   small_frame = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5)
   face_locations = face_recognition.face_locations(small_frame) # обнаружить лицо
   if face_locations:
          end_time_max = datetime.datetime.now()
          delta_time_max = end_time_max - start_time
          if int((str(delta_time_max).split(":")[2]).split(".")[0]) >0.8:   
            cv2.imwrite("tmp_fase/"+str(name)+"_"+str(datetime.datetime.now())+'.jpg',frame)
            start_time = datetime.datetime.now()
            cv2.circle(frame,(80,80), 55,(0,255,0), -1)
            yyy=yyy+1
            for (top, right, bottom, left) in (face_locations):
                  top *= 2
                  right *= 2
                  bottom *= 2
                  left *= 2
                  cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 12)               
   cv2.namedWindow("result", cv2.WINDOW_NORMAL)
   cv2.imshow('result', frame)
   k = cv2.waitKey(50) & 0xff
   if k == 27:
        break
cv2.destroyAllWindows()



